//修改密码
app.factory("commonControllers", function ($http, $q, $rootScope,$uibModal){
    $rootScope.changePwd = function (user) {
        var modal = $uibModal.open({
            animation: false,
            size:'',
            templateUrl: 'password.html',
            controller: 'changePassword',
            resolve: {user: function(){return user}}
        });
        modal.result.then(function () {
            user.password = user.newPass;
        }, function () {
            console.info('Modal dismissed at: ' + new Date());
        });
    }
    return {

    }
});

app.controller('changePassword', function ($scope,$http,$uibModalInstance,user,fac) {
    $scope.user=user;
    $scope.save = function(form){
        form.$setSubmitted(true);
        if (!form.$valid) {
            return;
        }
        if(user.newPass!=user.repeatPass){
            alert("两次密码不一致！")
            return;
        }
        //后端交互
        $http.post("/sys/changePassword", {oldPass:user.oldPass,newPass:user.newPass},fac.postConfig).success(function(resp){
            if(resp.code===0){
                msg("修改成功！");
                $uibModalInstance.close();
                /*      $scope.redirect=setTimeout(function(){
                          location.href = "login.html";
                      },1000)*/
            }else{
                alert(resp.msg);
            }
        })
    }
});